package com.example.module_message.ui


import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.lib_common.base.BaseFragment
import com.example.lib_common.base.BaseViewModel
import com.example.lib_common.utils.ToastUtils
import com.example.module_message.R
import com.example.module_message.databinding.FragmentMessageBinding
import com.example.module_message.model.MessageEntity
import com.example.module_message.ui.adapter.MessageAdapter
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MessageFragment : BaseFragment<BaseViewModel,FragmentMessageBinding>() {
    override val mLayoutResId: Int
        get() = R.layout.fragment_message
    private val mViewModel:MessageViewModel by viewModels()
    lateinit var msAdapter :MessageAdapter
    var list:ArrayList<MessageEntity> = arrayListOf()
    override fun initData() {
        msAdapter = MessageAdapter()
        mBinding.rv.adapter  = msAdapter
        mBinding.rv.layoutManager  = LinearLayoutManager(requireActivity())
        mViewModel.getMessageList("f2fb416f9fa54e83b16435a90d9e7f0a",1851)

        mViewModel.messageListLiveData.observe(this){
            if (it.isNullOrEmpty()) {
               ToastUtils.showLong(requireActivity(),  "没有数据") // 显示空状态
            } else {
                msAdapter.addMessageList(it)
            }
        }






    }

}